#include <stdio.h>
#include <string.h>
#include <limits.h>

char out[1000];
void reverse(char s[]);
void itoa(int n, char s[]);

int main()
{
    int n = -12345; 
  
    itoa(n, out);
    
    printf("n  =%d\nout=%s\n", n, out);
    return 0;
}

void reverse(char s[])
{
    int c, i, j;
    for (i = 0, j = strlen(s) - 1; i < j; i++, j--)
    {
        c = s[i];
        s[i] = s[j];
        s[j] = c;
    }
}

int sign;
void itoa(int n, char s[])
{
    static int i = 0;
    if(n < 0){
        sign = n;
        n = -n;        
    } 
    s[i++] = n % 10 + '0';
    n = n / 10;
    if(n > 0)
        itoa(n, s); 
    else
    {
        if(sign < 0) s[i++] = '-';
        s[i] = '\0';
        reverse(s);
    }
       
}